﻿var BlogOperate = {
    BlogShowUrl: "http://blog.baomihua.com/blog/",
    InterfaceUrl: "http://localhost:5092/interfaces/getblogshowoinfo.ashx",
    ErrorUrl:"http://online.baomihua.com/error/error.aspx",
    init:function(blogId){
        $.ajax({
            url: 'http://blog.baomihua.com/getblogstatus_1_' +blogID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var status=data.blogStatus;
                if(status=="0"){
                    window.location.href="http://online.baomihua.com/error/error.aspx";
                }
            }
        });
    },
    GetNewsBlogList: function (channelID) {
        $.ajax({
            url: 'http://blog.baomihua.com/getbloginfo_2_' + channelID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                $.each(data.blogList, function (i, item) {
                    html += " <h3><a target=\"_blank\" title=\"" + item.title + "\" href=\"http://blog.baomihua.com/blog/" + item.blogId + "\">" + item.title + "</a></h3>";
                });
                $("#NewBlogList").html(html);
            }
        });
    },
    GetHotBlogList: function (channelID) {
        $.ajax({
            url:   'http://blog.baomihua.com/getbloginfo_3_' + channelID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                $.each(data.blogList, function (i, item) {
                    html += " <h3><a target=\"_blank\" title=\"" + item.title + "\" href=\"http://blog.baomihua.com/blog/" + item.blogId + "\">" + item.title + "</a></h3>";
                });
                $("#HotBlogList").html(html);
            }
        });
    },
    GetUserBlogList: function (userID, channelID) {
        $.ajax({
            url: BlogOperate.InterfaceUrl + "?datatype=4&channelID=" + channelID + "&userid=" + userID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                var bloglist = data.blogList;
                if (bloglist.length > 0) {
                    html += "<div class=\"Btop\">";
                    html += "<span class=\"title\" id=\"span_bloglist_title\">该播客的其他博文</span> <span class=\"more\"><a href=\"http://www.baomihua.com/home/" + userID + "_5\">更多</a></span></div>";
                    html += "<div class=\"showblock\" id=\"span_bloglist\"><div class=\"box\">";
                    $.each(data.blogList, function (i, item) {
                        html += " <h3><a target=\"_blank\" title=\"" + item.title + "\" href=\"http://blog.baomihua.com/blog/" + item.blogId + "\">" + item.title + "</a></h3>";
                    });
                    html += "</div></div>";
                    $("#UserBlogList").html(html);
                } else {
                    $("#UserBlogList").hide();
                }
            }
        });
    },
    GetUserImgList: function (userID) {
        $.ajax({
            url: BlogOperate.InterfaceUrl + "?datatype=5&channelID=0&userid=" + userID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                var bloglist = data.blogList;
                if (bloglist.length > 0) {
                    html += "<div class=\"Btop\">";
                    html += "<span class=\"title\" id=\"span_imagelist_title\">该播客的图片</span> <span class=\"more\"><a href=\"http://www.baomihua.com/home/" + userID + "_4\">更多</a></span></div>";
                    html += "<div class=\"showblock\" id=\"span_ALbumList\"><div class=\"box\">";
                    $.each(data.blogList, function (i, item) {
                        html += "<ul><li class=\"vlink\"><a href=\"http://image.baomihua.com/img/" + item.imgId + "\" target=\"_blank\" title=\"" + item.photoName + "\"></a></li><li class=\"vimg\"><a href=\"http://image.baomihua.com/img/" + item.imgId + "\" title=\"" + item.photoName + "\" target=\"_blank\"><span><img class=\"resize_p\" src=\"" + item.photoUrl + "\" alt=\"" + item.photoName + "\"></span></a></li>";
                        html += "<li class=\"vtitle\"><a title=\"" + item.photoName + "\" target=\"_blank\" href=\"http://image.baomihua.com/img/" + item.imgId + "\">" + item.photoName + "</a></li></ul>";
                    });
                    html += "</div></div>";
                    $("#UserImgList").html(html);
                } else {
                    $("#UserImgList").hide();
                }
            }
        });
    },
    GetUserVideoList: function (userID) {
        $.ajax({
            url: BlogOperate.InterfaceUrl + "?datatype=6&channelID=0&userid=" + userID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                var bloglist = data.blogList;
                if (bloglist.length > 0) {
                    html += "<div class=\"Btop\">";
                    html += "<span class=\"title\" id=\"span_videolist_title\">该播客的最新视频</span> <span class=\"more\"><a href=\"http://www.baomihua.com/home/" + userID + "_3\">更多</a></span></div>";
                    html += "<div class=\"showblock\" id=\"span_videolist\"><div class=\"box\">";
                    $.each(data.blogList, function (i, item) {
                        var videoUrl = "http://video.baomihua.com/" + item.spaceUrl + "/" + item.videoId;
                        html += "<ul><li class=\"vlink\"><a href=\"" + videoUrl + "\" target=\"_blank\" title=\"" + item.videoName + "\"></a></li><li class=\"vimg\"><a href=\"" + videoUrl + "\" target=\"_blank\" title=\"" + item.videoName + "\"><span><img class=\"resize_s\" src=\"" + item.imgUrl + "\" alt=\"" + item.videoName + "\"></span></a></li><li class=\"vtitle\"><a href=\"" + videoUrl + "\" target=\"_blank\" title=\"" + item.videoName + "\">" + item.videoName + "</a></li></ul>";
                    });
                    $("#UserVideoList").html(html);
                } else {
                    $("#UserVideoList").hide();
                }
            }
        });
    },
    GetRecomBlogList: function ( channelID) {
        $.ajax({
            url: 'http://blog.baomihua.com/getbloginfo_7_' + channelID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                    var html = "";
                    var bloglist = data.blogList;
                     if (bloglist.length > 0) {
                         html+='<div class="hasPic clearfix">';
                         for(var i=0;i<bloglist.length && i<2;i++){
                            html+='<ul><li class="vimg"><a href="'+bloglist[i].linkUrl+'" title="'+bloglist[i].title+'" target="_blank"><span><img alt="'+bloglist[i].title+'" src="'+bloglist[i].imgUrl+'"></span></a></li>';
                            html+=' <li class="vtitle"><a title="'+bloglist[i].title+'" target="_blank" href="'+bloglist[i].linkUrl+'">'+bloglist[i].title+'</a></li></ul>';
                         }
                         html+="</div>";
                         if(bloglist.length >2){
                            html+='<div class="box">';
                            for(var j=2;j<bloglist.length;j++){
                                html+='<h3><a title="'+bloglist[j].title+'" href="'+bloglist[j].linkUrl+'">'+bloglist[j].title+'</a></h3>';
                            }
                            html+="</div>";
                         }
                         $("#RecomBlogList").html(html);
                     }
                     else
                     {
                        $("#RecomBlogList").hide();
                     }
             }
        });
    },
    GetRecomImgList:function(channelID){
         $.ajax({
            url: 'http://blog.baomihua.com/getbloginfo_8_' + channelID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                var bloglist = data.blogLis;
                $.each(data.blogList, function (i, item) {
                    html+='<ul><li class="vimg"><a href="'+item.linkUrl+'" title="'+item.title+'" target="_blank"><img src="'+item.imgUrl+'" alt="'+item.title+'"></a></li>';
                    html+='<li class="vtitle"><a title="'+item.title+'" target="_blank" href="'+item.linkUrl+'">'+item.title+'</a></li></ul>';    
                });
                $("#RecomImgList").html(html);
            }
        });
    },
    GetRecomVideoList:function(channelID){
        $.ajax({
            url: 'http://blog.baomihua.com/getbloginfo_9_' + channelID,
            dataType: 'jsonp',
            jsonp: 'jsoncallback',
            success: function (data) {
                var html = "";
                var bloglist = data.blogLis;
                $.each(data.blogList, function (i, item) {
                    html+='<ul><li class="vimg"><a href="'+item.linkUrl+'" target="_blank" title="'+item.title+'"><img src="'+item.imgUrl+'" alt="'+item.title+'"></a></li>';
                    html+='<li class="vtitle"><a href="'+item.linkUrl+'" target="_blank" title="'+item.title+'">'+item.title+'</a></li></ul>';
                });
                $("#RecomVideoList").html(html);
            }
        });
    }
};
    (function ($) {
        $.fn.lazyload = function (options) {
            var settings = {
                threshold: 0,
                failurelimit: 0,
                event: "scroll",
                effect: "show",
                container: window
            };
            if (options) {
                $.extend(settings, options)
            }
            var elements = this;
            if ("scroll" == settings.event) {
                $(settings.container).bind("scroll",function (event) {
                    var counter = 0;
                    elements.each(function () {
                        if (!$.belowthefold(this, settings) && !$.rightoffold(this, settings)) {
                            $(this).trigger("appear");
                        } else {
                            if (counter++ > settings.failurelimit) {
                                return false
                            }
                        }
                    });
                    var temp = $.grep(elements,function (element) {
                        return !element.loaded
                    });
                    elements = $(temp)
                })
            }
            return this.each(function () {
                var self = this;
                if ("scroll" != settings.event || $.belowthefold(self, settings) || $.rightoffold(self, settings)) {
                    if (settings.placeholder) {
                        $(self).attr("src", settings.placeholder);
                    }
                    self.loaded = false
                } else {
                    self.loaded = true;
                    if (settings.callback) {
                        settings.callback();
                    } else {
                        $(self).attr("src", $(self).attr("original"));
                    }
                }
                $(self).one("appear",function () {
                    if (!this.loaded) {
                        if (settings.callback) {
                            settings.callback();
                        } else {
                            $("<img />").bind("load",function () {
                                $(self).hide().attr("src", $(self).attr("original"))[settings.effect](settings.effectspeed);
                                self.loaded = true
                            }).attr("src", $(self).attr("original"))
                        }
                    }
                });
                if ("scroll" != settings.event) {
                    $(self).bind(settings.event,function (event) {
                        if (!self.loaded) {
                            $(self).trigger("appear")
                        }
                    })
                }
            })
        };
        $.belowthefold = function (element, settings) {
            if (settings.container === undefined || settings.container === window) {
                var fold = $(window).height() + $(window).scrollTop()
            } else {
                var fold = $(settings.container).offset().top + $(settings.container).height()
            }
            return fold <= $(element).offset().top - settings.threshold
        };
        $.rightoffold = function (element, settings) {
            if (settings.container === undefined || settings.container === window) {
                var fold = $(window).width() + $(window).scrollLeft()
            } else {
                var fold = $(settings.container).offset().left + $(settings.container).width()
            }
            return fold <= $(element).offset().left - settings.threshold
        };
        $.extend($.expr[':'], {
            "below-the-fold": "$.belowthefold(a, {threshold : 0, container: window})",
            "above-the-fold": "!$.belowthefold(a, {threshold : 0, container: window})",
            "right-of-fold": "$.rightoffold(a, {threshold : 0, container: window})",
            "left-of-fold": "!$.rightoffold(a, {threshold : 0, container: window})"
        })
    })(jQuery);var blogID = $("#hBlogID").val();
//BlogOperate.init(blogID);

 var AUserID=$("#AuthorUserID").val();
 $("#NewBlogList").lazyload({ effect: "fadeIn", callback: function () {
     var channelID = $("#hChannelID").val();
     if (channelID == -1) {
         channelID = 600;
     }
     BlogOperate.GetNewsBlogList(channelID);
 }
});
$("#HotBlogList").lazyload({ effect: "fadeIn", callback: function () {
    var channelID = $("#hChannelID").val();
    if (channelID == -1) {
        channelID = 600;
    }
    BlogOperate.GetHotBlogList(channelID);
}
});$("#RecomBlogList").lazyload({ effect: "fadeIn", callback: function () {
    var channelID = $("#hChannelID").val();
    if (channelID == -1) {
        channelID = 601;
    }
    BlogOperate.GetRecomBlogList(channelID);
}
});$("#RecomVideoList").lazyload({ effect: "fadeIn", callback: function () {
    var channelID = $("#hChannelID").val();
    if (channelID == -1) {
        channelID = 601;
    }
    BlogOperate.GetRecomVideoList(channelID);
}
});$("#RecomImgList").lazyload({ effect: "fadeIn", callback: function () {
    var channelID = $("#hChannelID").val();
    if (channelID == -1) {
        channelID = 601;
    }
    BlogOperate.GetRecomImgList(channelID);
}
});